package com.ddzh.controller;

import com.ddzh.pojo.User;
import com.ddzh.service.UserService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {

    @Reference
    private UserService userService;

    /**
     * 保存用户:
     * @param user
     * @return
     */
    @RequestMapping("/save")
    public boolean save(User user){
        System.out.println("user = " + user.toString());
        return userService.save(user);
    }

    /**
     * 删除用户
     * @param userId
     * @return
     * @RequestParam("userId") Integer id
     */
    @RequestMapping("/deleteUser")
    public boolean deleteUser(int userId){
        System.out.println("删除请求发送成功。。。。。。。。。。。。 id= "+ userId);
        return userService.removeById(userId);
    }

    /**
     * 根据用户id更新数据@RequestBody
     * @param user
     * @return
     */
    @RequestMapping("/updateUserById")
    public boolean updateUserById(User  user){
        System.out.println("user = " + user);
        return userService.updateById(user);
    }

    /**
     * 查询所有
     * @return
     */
    @RequestMapping("/findall")
    public List<User> findAll(){
        return userService.list();
    }

}
